package nio;

import java.nio.*;

/**
 * @author RJA
 * @version V1.0
 * @Title: nio.demo_1
 * @Description:
 * @date 2019/9/2 11:07
 */
public class NioTest01 {
    public static void main(String[] args) {
        IntBuffer intBuffer = IntBuffer.allocate(10);
        for(int i = 0;i < 10;++i){
            intBuffer.put(i);
            System.out.println("capacity: " + intBuffer.capacity());
            System.out.println("limit: " + intBuffer.limit());
            System.out.println("position: " + intBuffer.position());
        }
        intBuffer.flip();
        System.out.println("flip:===========================");
        System.out.println("capacity: " + intBuffer.capacity());
        System.out.println("limit: " + intBuffer.limit());
        System.out.println("position: " + intBuffer.position());
        for(int i = 0;i < 5;++i){
            System.out.println(intBuffer.get());
            System.out.println("capacity: " + intBuffer.capacity());
            System.out.println("limit: " + intBuffer.limit());
            System.out.println("position: " + intBuffer.position());
        }
        intBuffer.flip();
        System.out.println("flip2:===========================");
        while (intBuffer.remaining() > 0){
            System.out.println(intBuffer.get());
        }
        intBuffer.clear();
        System.out.println("clear========================");
        while (intBuffer.remaining() > 0){
            System.out.println(intBuffer.get());
        }
    }
}
